<?php
/**
 * @version   1.17 March 15, 2011
 * @author    RocketTheme, LLC http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2011 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */
/*
Plugin Name: RokStories
Plugin URI: http://www.rockettheme.com
Description: RokStories is a great widget to display your posts and accompanying images as a featured item. The widget itself is facilitated by Mootools to transition between images and articles seamlessly. Perfect for showcasing featured posts or image on your site.
Author: RocketTheme, LLC
Version: 1.17
Author URI: http://www.rockettheme.com
License: http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
*/

// Globals

global $rokstories_plugin_path, $rokstories_plugin_url, $platform;
$rokstories_plugin_path = dirname($plugin);
$rokstories_plugin_url = WP_PLUGIN_URL.'/'.basename($rokstories_plugin_path);

require(dirname(__FILE__).'/rokbrowser_check.php');

$browser_check = new RokBrowserCheck;
$platform = $browser_check->platform;

// Widget

class RokStoriesWidget extends WP_Widget {

	// RocketTheme RokStories Widget
	// Port by Jakub Baran

    function RokStoriesWidget() {
    	$widget_ops = array('classname' => 'widget_rokstories', 'description' => 'RocketTheme RokStories Widget');
    	$control_ops = array('width' => 700, 'height' => 400);
        $this->WP_Widget('widget-rokstories', 'RokStories', $widget_ops, $control_ops);
    }

    function widget($args, $instance){
 		extract($args);
 		$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
 		$rokstories_layout = empty($instance['rokstories_layout']) ? 'layout4' : $instance['rokstories_layout'];
 		$rokstories_display = empty($instance['rokstories_display']) ? 'content' : $instance['rokstories_display'];
 		$rokstories_type = empty($instance['rokstories_type']) ? 'post' : $instance['rokstories_type'];
 		$rokstories_cat = empty($instance['rokstories_cat']) ? 'uncategorized' : $instance['rokstories_cat'];
 		$rokstories_artcount = empty($instance['rokstories_artcount']) ? '6' : $instance['rokstories_artcount'];
 		$rokstories_order = empty($instance['rokstories_order']) ? 'date' : $instance['rokstories_order'];
 		$rokstories_contentpos = empty($instance['rokstories_contentpos']) ? 'none' : $instance['rokstories_contentpos'];
 		$rokstories_title = empty($instance['rokstories_title']) ? 'true' : $instance['rokstories_title'];
 		$rokstories_date = empty($instance['rokstories_date']) ? 'false' : $instance['rokstories_date'];
 		$rokstories_content = empty($instance['rokstories_content']) ? 'false' : $instance['rokstories_content'];
 		$rokstories_readmore = empty($instance['rokstories_readmore']) ? 'true' : $instance['rokstories_readmore'];
 		$rokstories_legacy_readmore = empty($instance['rokstories_legacy_readmore']) ? 'true' : $instance['rokstories_legacy_readmore'];
 		$rokstories_readmore_label = empty($instance['rokstories_readmore_label']) ? 'Read the Full Story' : $instance['rokstories_readmore_label'];
 		$rokstories_fixedheight = empty($instance['rokstories_fixedheight']) ? '0' : $instance['rokstories_fixedheight'];
 		$rokstories_thumbbox = empty($instance['rokstories_thumbbox']) ? 'auto' : $instance['rokstories_thumbbox'];
 		$rokstories_firstart = empty($instance['rokstories_firstart']) ? '0' : $instance['rokstories_firstart'];
 		$rokstories_thumbopa = empty($instance['rokstories_thumbopa']) ? '1' : $instance['rokstories_thumbopa'];
 		$rokstories_interact = empty($instance['rokstories_interact']) ? 'click' : $instance['rokstories_interact'];
 		$rokstories_autoplay = empty($instance['rokstories_autoplay']) ? '0' : $instance['rokstories_autoplay'];
 		$rokstories_autoplaydelay = empty($instance['rokstories_autoplaydelay']) ? '5000' : $instance['rokstories_autoplaydelay'];
 		$rokstories_labeltitle = empty($instance['rokstories_labeltitle']) ? 'false' : $instance['rokstories_labeltitle'];
 		$rokstories_preview = empty($instance['rokstories_preview']) ? '0' : $instance['rokstories_preview'];
 		$rokstories_fixedpreview = empty($instance['rokstories_fixedpreview']) ? '1' : $instance['rokstories_fixedpreview'];
 		$rokstories_linklabel = empty($instance['rokstories_linklabel']) ? 'false' : $instance['rokstories_linklabel'];
 		$rokstories_linkimage = empty($instance['rokstories_linkimage']) ? '0' : $instance['rokstories_linkimage'];
 		$rokstories_arrows = empty($instance['rokstories_arrows']) ? 'false' : $instance['rokstories_arrows'];
 		$rokstories_arrows_placement = empty($instance['rokstories_arrows_placement']) ? 'inside' : $instance['rokstories_arrows_placement'];
 		$rokstories_showmask = empty($instance['rokstories_showmask']) ? '0' : $instance['rokstories_showmask'];
 		$rokstories_descanim = empty($instance['rokstories_descanim']) ? 'bottomup' : $instance['rokstories_descanim'];
 		$rokstories_imganim = empty($instance['rokstories_imganim']) ? 'bottomup' : $instance['rokstories_imganim'];
 		$rokstories_scrollerduration = empty($instance['rokstories_scrollerduration']) ? '5000' : $instance['rokstories_scrollerduration'];
 		$rokstories_scrollertransition = empty($instance['rokstories_scrollertransition']) ? 'Expo.easeInOut' : $instance['rokstories_scrollertransition'];
 		$rokstories_imgw = empty($instance['rokstories_imgw']) ? '620' : $instance['rokstories_imgw'];
 		$rokstories_imgh = empty($instance['rokstories_imgh']) ? '246' : $instance['rokstories_imgh'];
 		$rokstories_thumbw = empty($instance['rokstories_thumbw']) ? '90' : $instance['rokstories_thumbw'];
 		$rokstories_thumbh = empty($instance['rokstories_thumbh']) ? '41' : $instance['rokstories_thumbh'];
 		$rokstories_left_offset_x = empty($instance['rokstories_left_offset_x']) ? '-40' : $instance['rokstories_left_offset_x'];
 		$rokstories_left_offset_y = empty($instance['rokstories_left_offset_y']) ? '-100' : $instance['rokstories_left_offset_y'];
 		$rokstories_right_offset_x = empty($instance['rokstories_right_offset_x']) ? '-30' : $instance['rokstories_right_offset_x'];
 		$rokstories_right_offset_y = empty($instance['rokstories_right_offset_y']) ? '-100' : $instance['rokstories_right_offset_y'];
 		$rokstories_left_f_offset_x = empty($instance['rokstories_left_f_offset_x']) ? '-55' : $instance['rokstories_left_f_offset_x'];
 		$rokstories_left_f_offset_y = empty($instance['rokstories_left_f_offset_y']) ? '-105' : $instance['rokstories_left_f_offset_y'];
 		$rokstories_right_f_offset_x = empty($instance['rokstories_right_f_offset_x']) ? '-55' : $instance['rokstories_right_f_offset_x'];
 		$rokstories_right_f_offset_y = empty($instance['rokstories_right_f_offset_y']) ? '-105' : $instance['rokstories_right_f_offset_y'];
 		$rokstories_image_generator = empty($instance['rokstories_image_generator']) ? 'default' : $instance['rokstories_image_generator'];

 		# Before the widget
 		echo $before_widget;

 		# The title
 		if ( $title )
 		echo $before_title . $title . $after_title;

  		# Content
  		
  		global $post, $more, $rokstories_plugin_path, $rokstories_plugin_url;
			
		$original_stuff = $args['widget_id'];
		$id = (int) str_replace("widget-rokstories-", "", $original_stuff);
		
		$catid = get_category_by_slug($rokstories_cat);
		
		$tlx = $rokstories_left_offset_x;
		$tly = $rokstories_left_offset_y;
		$trx = $rokstories_right_offset_x;
		$try = $rokstories_right_offset_y;
		
		if ($rokstories_fixedpreview == 0) {
			$tlx = $rokstories_left_f_offset_x;
			$tly = $rokstories_left_f_offset_y;
			$trx = $rokstories_right_f_offset_x;
			$try = $rokstories_right_f_offset_y;
		}
		
		$leftOffset = "{x: $tlx, y: $tly}";
		$rightOffset = "{x: $trx, y: $try}";
		
		$height = $rokstories_fixedheight;
		if ($height != 0 && $height != '0') $style = 'style="height: '.$height.'px;"';
		else $style = "";
		
		$image_pad = '';
		$content_pad = '';
		if($rokstories_contentpos == 'right') $image_pad = ' feature-pad';
		if($rokstories_contentpos == 'left') $content_pad = ' feature-pad';
		
		$contentOptions = ($rokstories_title == 'true' || $rokstories_date == 'true' || $rokstories_content == 'true' || $rokstories_readmore == 'true');
		
		if($rokstories_type == 'post') : $query_type = 'post_type='.$rokstories_type.'&cat='.$catid->term_id; endif;
		if($rokstories_type == 'page') : $query_type = 'post_type='.$rokstories_type; endif;

		?>
		
		<?php if(get_posts($query_type.'&meta_key=_rokstories_image')) { ?>
		
  		<script type="text/javascript">
  		/* <![CDATA[ */
  		
  			RokStoriesImage['rokstories-<?php echo $id; ?>'] = [];
  			
  			<?php if($rokstories_linkimage == 'true') { ?>
  			
			RokStoriesLinks['rokstories-<?php echo $id; ?>'] = [];
			
			<?php } ?>
  		
  			<?php $rokstories = new WP_Query($query_type.'&meta_key=_rokstories_image&posts_per_page='.$rokstories_artcount.'&orderby='.$rokstories_order);
    		if($rokstories->have_posts()) : while($rokstories->have_posts()) : $rokstories->the_post(); ?>
  			
  			<?php $image = get_post_meta($post->ID, '_rokstories_image', TRUE); ?>
  			
  			<?php if($rokstories_image_generator == 'default') :
  			
  				$img = rokstories_resize('', $image, $rokstories_imgw, $rokstories_imgh, true); ?>
  			
  				RokStoriesImage['rokstories-<?php echo $id; ?>'].push('<?php echo $img['url']; ?>');
  		
  			<?php else : ?>
  		
	   			RokStoriesImage['rokstories-<?php echo $id; ?>'].push('<?php echo $rokstories_plugin_url.'/thumb.php?src='.$image.'&w='.$rokstories_imgw.'&h='.$rokstories_imgh.'&zc=1&q=75'; ?>');
   			
   			<?php endif; ?>
   			
   			<?php if($rokstories_linkimage == 'true') { ?>
   			
			RokStoriesLinks['rokstories-<?php echo $id; ?>'].push('<?php the_permalink(); ?>');
			
			<?php } ?>
			
			<?php endwhile; endif; ?>
			
			window.addEvent('domready', function() {
				new RokStories('rokstories-<?php echo $id; ?>', {
					'id': <?php echo $id; ?>,
 					'startElement': <?php echo $rokstories_firstart; ?>,
					'thumbsOpacity': <?php echo $rokstories_thumbopa; ?>,
					'mousetype': '<?php echo $rokstories_interact; ?>',
					'autorun': <?php echo $rokstories_autoplay; ?>,
					'delay': <?php echo $rokstories_autoplaydelay; ?>,
					'scrollerDuration': <?php echo $rokstories_scrollerduration; ?>,
					'scrollerTransition': Fx.Transitions.<?php echo $rokstories_scrollertransition; ?>,
					'startWidth': '<?php echo $rokstories_thumbbox; ?>',
					'layout': '<?php echo $rokstories_layout; ?>',
					'linkedImgs': <?php echo $rokstories_linkimage; ?>,
					'showThumbs': <?php echo $rokstories_preview; ?>,
					'fixedThumb': <?php echo $rokstories_fixedpreview; ?>,
					'mask': <?php echo $rokstories_showmask; ?>,
					'descsAnim': '<?php echo $rokstories_descanim; ?>',
					'imgsAnim': '<?php echo $rokstories_imganim; ?>',
					'thumbLeftOffsets': <?php echo $leftOffset; ?>,
					'thumbRightOffsets': <?php echo $rightOffset; ?>
				});
			});
		
		/* ]]> */	
		</script>
		
		<?php 
		
			if($rokstories_layout == 'layout3') : 
				if(file_exists(TEMPLATEPATH.'/html/plugins/wp_rokstories/layout3.php')) :	
			  		require(TEMPLATEPATH.'/html/plugins/wp_rokstories/layout3.php');
			  	else :
	  		  		require($rokstories_plugin_path.'/tmpl/layout3.php'); 
	  		  	endif;
			elseif($rokstories_layout == 'layout4') :
				if(file_exists(TEMPLATEPATH.'/html/plugins/wp_rokstories/layout4.php')) :	
			  		require(TEMPLATEPATH.'/html/plugins/wp_rokstories/layout4.php');
			  	else :
	  		  		require($rokstories_plugin_path.'/tmpl/layout4.php'); 
	  		  	endif;
			elseif($rokstories_layout == 'layout5') :
				if(file_exists(TEMPLATEPATH.'/html/plugins/wp_rokstories/layout5.php')) :	
			  		require(TEMPLATEPATH.'/html/plugins/wp_rokstories/layout5.php');
			  	else :
	  		  		require($rokstories_plugin_path.'/tmpl/layout5.php'); 
	  		  	endif;					
			else :
				if(file_exists(TEMPLATEPATH.'/html/plugins/wp_rokstories/default.php')) :	
			  		require(TEMPLATEPATH.'/html/plugins/wp_rokstories/default.php');
			  	else :
	  		  		require($rokstories_plugin_path.'/tmpl/default.php'); 
	  		  	endif;	
			endif; 
		
		?>
		
		<?php wp_reset_query(); ?>
		
		<?php } else {
		
		_e('Sorry, but your category is empty or you don\'t have any post/page with RokStories image link!', 'rokstories');
		
		} ?>
		
		<?php
	
    	# After the widget
    	echo $after_widget;
	}

    function update($new_instance, $old_instance) {
    
    	$instance = $old_instance;
    	$instance['title'] = stripslashes($new_instance['title']);
    	$instance['rokstories_layout'] = stripslashes($new_instance['rokstories_layout']);
    	$instance['rokstories_display'] = stripslashes($new_instance['rokstories_display']);
    	$instance['rokstories_type'] = stripslashes($new_instance['rokstories_type']);
    	$instance['rokstories_cat'] = stripslashes($new_instance['rokstories_cat']);
    	$instance['rokstories_artcount'] = stripslashes($new_instance['rokstories_artcount']);
    	$instance['rokstories_order'] = stripslashes($new_instance['rokstories_order']);
    	$instance['rokstories_contentpos'] = stripslashes($new_instance['rokstories_contentpos']);
    	$instance['rokstories_title'] = stripslashes($new_instance['rokstories_title']);
    	$instance['rokstories_date'] = stripslashes($new_instance['rokstories_date']);
    	$instance['rokstories_content'] = stripslashes($new_instance['rokstories_content']);
    	$instance['rokstories_readmore'] = stripslashes($new_instance['rokstories_readmore']);
    	$instance['rokstories_legacy_readmore'] = stripslashes($new_instance['rokstories_legacy_readmore']);
    	$instance['rokstories_readmore_label'] = stripslashes($new_instance['rokstories_readmore_label']);
    	$instance['rokstories_fixedheight'] = stripslashes($new_instance['rokstories_fixedheight']);
    	$instance['rokstories_thumbbox'] = stripslashes($new_instance['rokstories_thumbbox']);
    	$instance['rokstories_firstart'] = stripslashes($new_instance['rokstories_firstart']);
    	$instance['rokstories_thumbopa'] = stripslashes($new_instance['rokstories_thumbopa']);
    	$instance['rokstories_interact'] = stripslashes($new_instance['rokstories_interact']);
    	$instance['rokstories_autoplay'] = stripslashes($new_instance['rokstories_autoplay']);
    	$instance['rokstories_autoplaydelay'] = stripslashes($new_instance['rokstories_autoplaydelay']);
    	$instance['rokstories_labeltitle'] = stripslashes($new_instance['rokstories_labeltitle']);
    	$instance['rokstories_preview'] = stripslashes($new_instance['rokstories_preview']);
    	$instance['rokstories_fixedpreview'] = stripslashes($new_instance['rokstories_fixedpreview']);
    	$instance['rokstories_linklabel'] = stripslashes($new_instance['rokstories_linklabel']);
    	$instance['rokstories_linkimage'] = stripslashes($new_instance['rokstories_linkimage']);
    	$instance['rokstories_arrows'] = stripslashes($new_instance['rokstories_arrows']);
    	$instance['rokstories_arrows_placement'] = stripslashes($new_instance['rokstories_arrows_placement']);
    	$instance['rokstories_showmask'] = stripslashes($new_instance['rokstories_showmask']);
    	$instance['rokstories_descanim'] = stripslashes($new_instance['rokstories_descanim']);
    	$instance['rokstories_imganim'] = stripslashes($new_instance['rokstories_imganim']);
    	$instance['rokstories_scrollerduration'] = stripslashes($new_instance['rokstories_scrollerduration']);
    	$instance['rokstories_scrollertransition'] = stripslashes($new_instance['rokstories_scrollertransition']);
    	$instance['rokstories_imgw'] = stripslashes($new_instance['rokstories_imgw']);
    	$instance['rokstories_imgh'] = stripslashes($new_instance['rokstories_imgh']);
    	$instance['rokstories_thumbw'] = stripslashes($new_instance['rokstories_thumbw']);
    	$instance['rokstories_thumbh'] = stripslashes($new_instance['rokstories_thumbh']);
    	$instance['rokstories_left_offset_x'] = stripslashes($new_instance['rokstories_left_offset_x']);
    	$instance['rokstories_left_offset_y'] = stripslashes($new_instance['rokstories_left_offset_y']);
    	$instance['rokstories_right_offset_x'] = stripslashes($new_instance['rokstories_right_offset_x']);
    	$instance['rokstories_right_offset_y'] = stripslashes($new_instance['rokstories_right_offset_y']);
    	$instance['rokstories_left_f_offset_x'] = stripslashes($new_instance['rokstories_left_f_offset_x']);
    	$instance['rokstories_left_f_offset_y'] = stripslashes($new_instance['rokstories_left_f_offset_y']);
    	$instance['rokstories_right_f_offset_x'] = stripslashes($new_instance['rokstories_right_f_offset_x']);
    	$instance['rokstories_right_f_offset_y'] = stripslashes($new_instance['rokstories_right_f_offset_y']);
    	$instance['rokstories_image_generator'] = stripslashes($new_instance['rokstories_image_generator']);

 		return $instance;
	}

    function form($instance){
    
    	global $rokstories_plugin_path, $rokstories_plugin_url;
   		
   		//Defaults
   		
  		$instance = wp_parse_args( (array) $instance, array('title'=>'', 'rokstories_layout'=>'layout4', 'rokstories_display'=>'content', 'rokstories_type'=>'post', 'rokstories_cat'=>'uncategorized', 'rokstories_artcount'=>'6', 'rokstories_order'=>'date', 'rokstories_contentpos'=>'none', 'rokstories_title'=>'true', 'rokstories_date'=>'false', 'rokstories_content'=>'false', 'rokstories_readmore'=>'true', 'rokstories_legacy_readmore' => 'true', 'rokstories_readmore_label' => 'Read the Full Story', 'rokstories_fixedheight'=>'0', 'rokstories_thumbbox'=>'auto', 'rokstories_firstart'=>'0', 'rokstories_thumbopa'=>'1', 'rokstories_interact'=>'click', 'rokstories_autoplay'=>'0', 'rokstories_autoplaydelay'=>'5000', 'rokstories_labeltitle'=>'false', 'rokstories_preview'=>'0', 'rokstories_fixedpreview'=>'1', 'rokstories_linklabel'=>'false', 'rokstories_linkimage'=>'0', 'rokstories_arrows'=>'false', 'rokstories_arrows_placement'=>'inside', 'rokstories_showmask'=>'0', 'rokstories_descanim'=>'bottomup', 'rokstories_imganim'=>'bottomup', 'rokstories_scrollerduration' => '5000', 'rokstories_scrollertransition' => 'Expo.easeInOut', 'rokstories_imgw'=>'620', 'rokstories_imgh'=>'246', 'rokstories_thumbw'=>'90', 'rokstories_thumbh'=>'41', 'rokstories_left_offset_x'=>'-40', 'rokstories_left_offset_y'=>'-100', 'rokstories_right_offset_x'=>'-30', 'rokstories_right_offset_y'=>'-100', 'rokstories_left_f_offset_x'=>'-55', 'rokstories_left_f_offset_y'=>'-105', 'rokstories_right_f_offset_x'=>'-55', 'rokstories_right_f_offset_y'=>'-105', 'rokstories_image_generator'=>'default' ) );

   		$title = htmlspecialchars($instance['title']);
   		$rokstories_layout = htmlspecialchars($instance['rokstories_layout']);
   		$rokstories_display = htmlspecialchars($instance['rokstories_display']);
   		$rokstories_type = htmlspecialchars($instance['rokstories_type']);
   		$rokstories_cat = htmlspecialchars($instance['rokstories_cat']);
   		$rokstories_artcount = htmlspecialchars($instance['rokstories_artcount']);
   		$rokstories_order = htmlspecialchars($instance['rokstories_order']);
   		$rokstories_contentpos = htmlspecialchars($instance['rokstories_contentpos']);
   		$rokstories_title = htmlspecialchars($instance['rokstories_title']);
   		$rokstories_date = htmlspecialchars($instance['rokstories_date']);
   		$rokstories_content = htmlspecialchars($instance['rokstories_content']);
   		$rokstories_readmore = htmlspecialchars($instance['rokstories_readmore']);
   		$rokstories_legacy_readmore = htmlspecialchars($instance['rokstories_legacy_readmore']);
   		$rokstories_readmore_label = htmlspecialchars($instance['rokstories_readmore_label']);
   		$rokstories_fixedheight = htmlspecialchars($instance['rokstories_fixedheight']);
   		$rokstories_thumbbox = htmlspecialchars($instance['rokstories_thumbbox']);
   		$rokstories_firstart = htmlspecialchars($instance['rokstories_firstart']);
   		$rokstories_thumbopa = htmlspecialchars($instance['rokstories_thumbopa']);
   		$rokstories_interact = htmlspecialchars($instance['rokstories_interact']);
   		$rokstories_autoplay = htmlspecialchars($instance['rokstories_autoplay']);
   		$rokstories_autoplaydelay = htmlspecialchars($instance['rokstories_autoplaydelay']);
   		$rokstories_labeltitle = htmlspecialchars($instance['rokstories_labeltitle']);
   		$rokstories_preview = htmlspecialchars($instance['rokstories_preview']);
   		$rokstories_fixedpreview = htmlspecialchars($instance['rokstories_fixedpreview']);
   		$rokstories_linklabel = htmlspecialchars($instance['rokstories_linklabel']);
   		$rokstories_linkimage = htmlspecialchars($instance['rokstories_linkimage']);
   		$rokstories_arrows = htmlspecialchars($instance['rokstories_arrows']);
   		$rokstories_arrows_placement = htmlspecialchars($instance['rokstories_arrows_placement']);
   		$rokstories_showmask = htmlspecialchars($instance['rokstories_showmask']);
   		$rokstories_descanim = htmlspecialchars($instance['rokstories_descanim']);
   		$rokstories_imganim = htmlspecialchars($instance['rokstories_imganim']);
   		$rokstories_scrollerduration = htmlspecialchars($instance['rokstories_scrollerduration']);
   		$rokstories_scrollertransition = htmlspecialchars($instance['rokstories_scrollertransition']);
   		$rokstories_imgw = htmlspecialchars($instance['rokstories_imgw']);
   		$rokstories_imgh = htmlspecialchars($instance['rokstories_imgh']);
   		$rokstories_thumbw = htmlspecialchars($instance['rokstories_thumbw']);
   		$rokstories_thumbh = htmlspecialchars($instance['rokstories_thumbh']);
   		$rokstories_left_offset_x = htmlspecialchars($instance['rokstories_left_offset_x']);
   		$rokstories_left_offset_y = htmlspecialchars($instance['rokstories_left_offset_y']);
   		$rokstories_right_offset_x = htmlspecialchars($instance['rokstories_right_offset_x']);
   		$rokstories_right_offset_y = htmlspecialchars($instance['rokstories_right_offset_y']);
   		$rokstories_left_f_offset_x = htmlspecialchars($instance['rokstories_left_f_offset_x']);
   		$rokstories_left_f_offset_y = htmlspecialchars($instance['rokstories_left_f_offset_y']);
   		$rokstories_right_f_offset_x = htmlspecialchars($instance['rokstories_right_f_offset_x']);
   		$rokstories_right_f_offset_y = htmlspecialchars($instance['rokstories_right_f_offset_y']);
   		$rokstories_image_generator = htmlspecialchars($instance['rokstories_image_generator']);

    	# Output the options
    	
    	$categories = get_terms('category', 'hide_empty=0&orderby=name');
    	
    	?>
    	
    	<div style="float:left; width: 50%; border-right: 1px dashed #919191;">
    	<h3><?php _e('General Parameters', 'rokstories'); ?></h3>
    	<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'rokstories'); ?>&nbsp;
    	<input style="width: 270px;" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_layout'); ?>"><?php _e('Layout', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_layout'); ?>" name="<?php echo $this->get_field_name('rokstories_layout'); ?>">
      		<option value="layout1"<?php selected( $instance['rokstories_layout'], 'layout1' ); ?>><?php _e('Default', 'rokstories'); ?></option>
      		<option value="layout2"<?php selected( $instance['rokstories_layout'], 'layout2' ); ?>><?php _e('Showcase', 'rokstories'); ?></option>
      		<option value="layout3"<?php selected( $instance['rokstories_layout'], 'layout3' ); ?>><?php _e('Compact Showcase', 'rokstories'); ?></option>
      		<option value="layout4"<?php selected( $instance['rokstories_layout'], 'layout4' ); ?>><?php _e('Compact Showcase with Numbers', 'rokstories'); ?></option>
      		<option value="layout5"<?php selected( $instance['rokstories_layout'], 'layout5' ); ?>><?php _e('Masked Showcase', 'rokstories'); ?></option>
        </select>
        <br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_type'); ?>"><?php _e('Type of Query', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_type'); ?>" name="<?php echo $this->get_field_name('rokstories_type'); ?>">
      		<option value="page"<?php selected( $instance['rokstories_type'], 'page' ); ?>><?php _e('Pages', 'rokstories'); ?></option>
      		<option value="post"<?php selected( $instance['rokstories_type'], 'post' ); ?>><?php _e('Posts', 'rokstories'); ?></option>
        </select>
        <br /><br />
        <label for="<?php echo $this->get_field_id('rokstories_cat'); ?>"><?php _e('Posts Category:', 'rokstories'); ?></label>&nbsp;
		<select name="<?php echo $this->get_field_name('rokstories_cat'); ?>" id="<?php echo $this->get_field_id('rokstories_cat'); ?>">
			<?php foreach ($categories as $cat) { ?>
				<option value="<?php echo $cat->slug; ?>"<?php if($rokstories_cat == $cat->slug) : echo ' selected="selected"'; endif; ?>><?php echo $cat->name; ?></option>
			<?php } ?>
		</select>
		<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_artcount'); ?>"><?php _e('Max Number Of Articles', 'rokstories'); ?>&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_artcount'); ?>" name="<?php echo $this->get_field_name('rokstories_artcount'); ?>" type="text" value="<?php echo $rokstories_artcount; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_order'); ?>"><?php _e('Order', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_order'); ?>" name="<?php echo $this->get_field_name('rokstories_order'); ?>">
      		<option value="author"<?php selected( $instance['rokstories_order'], 'author' ); ?>><?php _e('Author', 'rokstories'); ?></option>
      		<option value="date"<?php selected( $instance['rokstories_order'], 'date' ); ?>><?php _e('Date', 'rokstories'); ?></option>
      		<option value="title"<?php selected( $instance['rokstories_order'], 'title' ); ?>><?php _e('Title', 'rokstories'); ?></option>
      		<option value="modified"<?php selected( $instance['rokstories_order'], 'modified' ); ?>><?php _e('Modified', 'rokstories'); ?></option>
      		<option value="menu_order"<?php selected( $instance['rokstories_order'], 'menu_order' ); ?>><?php _e('Menu Order', 'rokstories'); ?></option>
      		<option value="parent"<?php selected( $instance['rokstories_order'], 'parent' ); ?>><?php _e('Parent', 'rokstories'); ?></option>
      		<option value="id"<?php selected( $instance['rokstories_order'], 'id' ); ?>>ID</option>
        </select>
        <br /><br />
        <label for="<?php echo $this->get_field_id('rokstories_contentpos'); ?>"><?php _e('Image Position', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_contentpos'); ?>" name="<?php echo $this->get_field_name('rokstories_contentpos'); ?>">
      		<option value="left"<?php selected( $instance['rokstories_contentpos'], 'left' ); ?>><?php _e('Left', 'rokstories'); ?></option>
      		<option value="right"<?php selected( $instance['rokstories_contentpos'], 'right' ); ?>><?php _e('Right', 'rokstories'); ?></option>
      		<option value="none"<?php selected( $instance['rokstories_contentpos'], 'none' ); ?>><?php _e('None', 'rokstories'); ?></option>
        </select>
        <br /><br />
        <?php _e('Display Article Title', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_title'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_title'); ?>" <?php if($rokstories_title=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_title'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_title'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_title'); ?>" <?php if($rokstories_title=='false') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_title'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<?php _e('Display Article Date', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_date'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_date'); ?>" <?php if($rokstories_date=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_date'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_date'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_date'); ?>" <?php if($rokstories_date=='false') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_date'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<?php _e('Display Article Content', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_content'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_content'); ?>" <?php if($rokstories_content=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_content'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_content'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_content'); ?>" <?php if($rokstories_content=='false') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_content'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<label for="<?php echo $this->get_field_id('rokstories_display'); ?>"><?php _e('Type Of Content', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_display'); ?>" name="<?php echo $this->get_field_name('rokstories_display'); ?>">
      		<option value="content"<?php selected( $instance['rokstories_display'], 'content' ); ?>><?php _e('Content', 'rokstories'); ?></option>
      		<option value="excerpt"<?php selected( $instance['rokstories_display'], 'excerpt' ); ?>><?php _e('Excerpt', 'rokstories'); ?></option>
        </select>
        <br /><br />
		<?php _e('Display \'Read More\' Button', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_readmore'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_readmore'); ?>" <?php if($rokstories_readmore=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_readmore'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_readmore'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_readmore'); ?>" <?php if($rokstories_readmore=='false') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_readmore'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<?php _e('\'Read More\' Style', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_legacy_readmore'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_legacy_readmore'); ?>" <?php if($rokstories_legacy_readmore=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_legacy_readmore'); ?>1"><?php _e('Legacy', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_legacy_readmore'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_legacy_readmore'); ?>" <?php if($rokstories_legacy_readmore=='false') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_legacy_readmore'); ?>0"><?php _e('Standard', 'rokstories'); ?></label>
		<br /><br />
		<label for="<?php echo $this->get_field_id('rokstories_readmore_label'); ?>"><?php _e('\'Read More\' Label', 'rokstories'); ?>&nbsp;
    	<input style="width: 210px;" id="<?php echo $this->get_field_id('rokstories_readmore_label'); ?>" name="<?php echo $this->get_field_name('rokstories_readmore_label'); ?>" type="text" value="<?php echo $rokstories_readmore_label; ?>" /></label>
    	<br /><br />
		<label for="<?php echo $this->get_field_id('rokstories_imgw'); ?>"><?php _e('Image Dimensions', 'rokstories'); ?>&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_imgw'); ?>" name="<?php echo $this->get_field_name('rokstories_imgw'); ?>" type="text" value="<?php echo $rokstories_imgw; ?>" />&nbsp;px</label>
    	&nbsp;&nbsp;x&nbsp;&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_imgh'); ?>" name="<?php echo $this->get_field_name('rokstories_imgh'); ?>" type="text" value="<?php echo $rokstories_imgh; ?>" />&nbsp;px
    	<br /><br />
		<label for="<?php echo $this->get_field_id('rokstories_thumbw'); ?>"><?php _e('Thumbnail Dimensions', 'rokstories'); ?>&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_thumbw'); ?>" name="<?php echo $this->get_field_name('rokstories_thumbw'); ?>" type="text" value="<?php echo $rokstories_thumbw; ?>" />&nbsp;px</label>
    	&nbsp;&nbsp;x&nbsp;&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_thumbh'); ?>" name="<?php echo $this->get_field_name('rokstories_thumbh'); ?>" type="text" value="<?php echo $rokstories_thumbh; ?>" />&nbsp;px
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_fixedheight'); ?>"><?php _e('RokStories Fixed Height', 'rokstories'); ?>&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_fixedheight'); ?>" name="<?php echo $this->get_field_name('rokstories_fixedheight'); ?>" type="text" value="<?php echo $rokstories_fixedheight; ?>" />&nbsp;px</label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_thumbbox'); ?>"><?php _e('Thumbnail Container Size', 'rokstories'); ?>&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_thumbbox'); ?>" name="<?php echo $this->get_field_name('rokstories_thumbbox'); ?>" type="text" value="<?php echo $rokstories_thumbbox; ?>" />&nbsp;px</label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_firstart'); ?>"><?php _e('First Article', 'rokstories'); ?>&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_firstart'); ?>" name="<?php echo $this->get_field_name('rokstories_firstart'); ?>" type="text" value="<?php echo $rokstories_firstart; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_thumbopa'); ?>"><?php _e('Thumbs Opacity', 'rokstories'); ?>&nbsp;
    	<input style="width: 40px;" id="<?php echo $this->get_field_id('rokstories_thumbopa'); ?>" name="<?php echo $this->get_field_name('rokstories_thumbopa'); ?>" type="text" value="<?php echo $rokstories_thumbopa; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_interact'); ?>"><?php _e('Interaction', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_interact'); ?>" name="<?php echo $this->get_field_name('rokstories_interact'); ?>">
      		<option value="click"<?php selected( $instance['rokstories_interact'], 'click' ); ?>><?php _e('Click', 'rokstories'); ?></option>
      		<option value="mouseenter"<?php selected( $instance['rokstories_interact'], 'mouseenter' ); ?>><?php _e('Mouse Over', 'rokstories'); ?></option>
        </select>
        <br /><br />
        <?php _e('Autoplay', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_autoplay'); ?>1" type="radio" value="1" name="<?php echo $this->get_field_name('rokstories_autoplay'); ?>" <?php if($rokstories_autoplay=='1') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_autoplay'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_autoplay'); ?>0" type="radio" value="0" name="<?php echo $this->get_field_name('rokstories_autoplay'); ?>" <?php if($rokstories_autoplay=='0') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_autoplay'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<label for="<?php echo $this->get_field_id('rokstories_autoplaydelay'); ?>"><?php _e('Autoplay Delay', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_autoplaydelay'); ?>" name="<?php echo $this->get_field_name('rokstories_autoplaydelay'); ?>" type="text" value="<?php echo $rokstories_autoplaydelay; ?>" />&nbsp;ms</label>
    	<br /><br />
    	</div>
    	<div style="float:left; width: 45%; padding-left: 15px;">
    	<h3><?php _e('Only for Showcase Type Layout', 'rokstories'); ?></h3>
    	<?php _e('Show Label Title', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_labeltitle'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_labeltitle'); ?>" <?php if($rokstories_labeltitle=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_labeltitle'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_labeltitle'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_labeltitle'); ?>" <?php if($rokstories_labeltitle!='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_labeltitle'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<?php _e('Show Previews on Arrows', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_preview'); ?>1" type="radio" value="1" name="<?php echo $this->get_field_name('rokstories_preview'); ?>" <?php if($rokstories_preview=='1') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_preview'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_preview'); ?>0" type="radio" value="0" name="<?php echo $this->get_field_name('rokstories_preview'); ?>" <?php if($rokstories_preview=='0') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_preview'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<?php _e('Fixed Previews', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_fixedpreview'); ?>1" type="radio" value="1" name="<?php echo $this->get_field_name('rokstories_fixedpreview'); ?>" <?php if($rokstories_fixedpreview=='1') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_fixedpreview'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_fixedpreview'); ?>0" type="radio" value="0" name="<?php echo $this->get_field_name('rokstories_fixedpreview'); ?>" <?php if($rokstories_fixedpreview=='0') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_fixedpreview'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<?php _e('Linked Labels', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_linklabel'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_linklabel'); ?>" <?php if($rokstories_linklabel=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_linklabel'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_linklabel'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_linklabel'); ?>" <?php if($rokstories_linklabel!='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_linklabel'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<?php _e('Linked Images', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_linkimage'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_linkimage'); ?>" <?php if($rokstories_linkimage=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_linkimage'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_linkimage'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_linkimage'); ?>" <?php if($rokstories_linkimage!='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_linkimage'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<?php _e('Image Arrows', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_arrows'); ?>1" type="radio" value="true" name="<?php echo $this->get_field_name('rokstories_arrows'); ?>" <?php if($rokstories_arrows=='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_arrows'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_arrows'); ?>0" type="radio" value="false" name="<?php echo $this->get_field_name('rokstories_arrows'); ?>" <?php if($rokstories_arrows!='true') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_arrows'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<label for="<?php echo $this->get_field_id('rokstories_arrows_placement'); ?>"><?php _e('Arrows Placement', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_arrows_placement'); ?>" name="<?php echo $this->get_field_name('rokstories_arrows_placement'); ?>">
      		<option value="inside"<?php selected( $instance['rokstories_arrows_placement'], 'inside' ); ?>><?php _e('Inside', 'rokstories'); ?></option>
      		<option value="outside"<?php selected( $instance['rokstories_arrows_placement'], 'outside' ); ?>><?php _e('Outside', 'rokstories'); ?></option>
        </select>
        <br /><br />
		<?php _e('Show Mask', 'rokstories'); ?>
        <input id="<?php echo $this->get_field_id('rokstories_showmask'); ?>1" type="radio" value="1" name="<?php echo $this->get_field_name('rokstories_showmask'); ?>" <?php if($rokstories_showmask=='1') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_showmask'); ?>1"><?php _e('Yes', 'rokstories'); ?></label>&nbsp;&nbsp;
		<input id="<?php echo $this->get_field_id('rokstories_showmask'); ?>0" type="radio" value="0" name="<?php echo $this->get_field_name('rokstories_showmask'); ?>" <?php if($rokstories_showmask=='0') echo 'checked="checked"'; ?>/>
		<label for="<?php echo $this->get_field_id('rokstories_showmask'); ?>0"><?php _e('No', 'rokstories'); ?></label>
		<br /><br />
		<label for="<?php echo $this->get_field_id('rokstories_descanim'); ?>"><?php _e('Description Animation', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_descanim'); ?>" name="<?php echo $this->get_field_name('rokstories_descanim'); ?>">
      		<option value="bottomup"<?php selected( $instance['rokstories_descanim'], 'bottomup' ); ?>><?php _e('Bottom Up', 'rokstories'); ?></option>
      		<option value="topdown"<?php selected( $instance['rokstories_descanim'], 'topdown' ); ?>><?php _e('Top Down', 'rokstories'); ?></option>
      		<option value="fade"<?php selected( $instance['rokstories_descanim'], 'fade' ); ?>><?php _e('Fade', 'rokstories'); ?></option>
        </select>
        <br /><br />
        <label for="<?php echo $this->get_field_id('rokstories_imganim'); ?>"><?php _e('Images Animation', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_imganim'); ?>" name="<?php echo $this->get_field_name('rokstories_imganim'); ?>">
      		<option value="bottomup"<?php selected( $instance['rokstories_imganim'], 'bottomup' ); ?>><?php _e('Bottom Up', 'rokstories'); ?></option>
      		<option value="topdown"<?php selected( $instance['rokstories_imganim'], 'topdown' ); ?>><?php _e('Top Down', 'rokstories'); ?></option>
      		<option value="fade"<?php selected( $instance['rokstories_imganim'], 'fade' ); ?>><?php _e('Fade', 'rokstories'); ?></option>
        </select>
        <br /><br />
        <label for="<?php echo $this->get_field_id('rokstories_scrollerduration'); ?>"><?php _e('Scroller Duration', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_scrollerduration'); ?>" name="<?php echo $this->get_field_name('rokstories_scrollerduration'); ?>" type="text" value="<?php echo $rokstories_scrollerduration; ?>" />&nbsp;ms</label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_scrollertransition'); ?>"><?php _e('Transition Effect:', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_scrollertransition'); ?>" name="<?php echo $this->get_field_name('rokstories_scrollertransition'); ?>">
      		<option value="linear"<?php selected( $instance['rokstories_scrollertransition'], 'linear' ); ?>>linear</option>
      		<option value="Quad.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Quad.easeOut' ); ?>>Quad.easeOut</option>
      		<option value="Quad.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Quad.easeIn' ); ?>>Quad.easeIn</option>
      		<option value="Quad.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Quad.easeInOut' ); ?>>Quad.easeInOut</option>
      		<option value="Cubic.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Cubic.easeOut' ); ?>>Cubic.easeOut</option>
      		<option value="Cubic.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Cubic.easeIn' ); ?>>Cubic.easeIn</option>
      		<option value="Cubic.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Cubic.easeInOut' ); ?>>Cubic.easeInOut</option>
      		<option value="Quart.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Quart.easeOut' ); ?>>Quart.easeOut</option>
      		<option value="Quart.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Quart.easeIn' ); ?>>Quart.easeIn</option>
      		<option value="Quart.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Quart.easeInOut' ); ?>>Quart.easeInOut</option>
      		<option value="Quint.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Quint.easeOut' ); ?>>Quint.easeOut</option>
      		<option value="Quint.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Quint.easeIn' ); ?>>Quint.easeIn</option>
      		<option value="Quint.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Quint.easeInOut' ); ?>>Quint.easeInOut</option>
      		<option value="Expo.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Expo.easeOut' ); ?>>Expo.easeOut</option>
      		<option value="Expo.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Expo.easeIn' ); ?>>Expo.easeIn</option>
      		<option value="Expo.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Expo.easeInOut' ); ?>>Expo.easeInOut</option>
      		<option value="Circ.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Circ.easeOut' ); ?>>Circ.easeOut</option>
      		<option value="Circ.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Circ.easeIn' ); ?>>Circ.easeIn</option>
      		<option value="Circ.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Circ.easeInOut' ); ?>>Circ.easeInOut</option>
      		<option value="Sine.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Sine.easeOut' ); ?>>Sine.easeOut</option>
      		<option value="Sine.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Sine.easeIn' ); ?>>Sine.easeIn</option>
      		<option value="Sine.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Sine.easeInOut' ); ?>>Sine.easeInOut</option>
      		<option value="Back.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Back.easeOut' ); ?>>Back.easeOut</option>
      		<option value="Back.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Back.easeIn' ); ?>>Back.easeIn</option>
      		<option value="Back.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Back.easeInOut' ); ?>>Back.easeInOut</option>
      		<option value="Bounce.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Bounce.easeOut' ); ?>>Bounce.easeOut</option>
      		<option value="Bounce.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Bounce.easeIn' ); ?>>Bounce.easeIn</option>
      		<option value="Bounce.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Bounce.easeInOut' ); ?>>Bounce.easeInOut</option>
      		<option value="Elastic.easeOut"<?php selected( $instance['rokstories_scrollertransition'], 'Elastic.easeOut' ); ?>>Elastic.easeOut</option>
      		<option value="Elastic.easeIn"<?php selected( $instance['rokstories_scrollertransition'], 'Elastic.easeIn' ); ?>>Elastic.easeIn</option>
      		<option value="Elastic.easeInOut"<?php selected( $instance['rokstories_scrollertransition'], 'Elastic.easeInOut' ); ?>>Elastic.easeInOut</option>
        </select>
        <br /><br />
        <hr style="border: none; border-bottom: 1px dashed #919191;" /><br />
        <label for="<?php echo $this->get_field_id('rokstories_image_generator'); ?>"><?php _e('Image Generator', 'rokstories'); ?></label>&nbsp;
    	<select id="<?php echo $this->get_field_id('rokstories_image_generator'); ?>" name="<?php echo $this->get_field_name('rokstories_image_generator'); ?>">
      		<option value="default"<?php selected( $instance['rokstories_image_generator'], 'default' ); ?>><?php _e('Default', 'rokstories'); ?></option>
      		<option value="timthumb"<?php selected( $instance['rokstories_image_generator'], 'timthumb' ); ?>>TimThumb</option>
        </select>
        <br /><br />
        <label for="<?php echo $this->get_field_id('rokstories_left_offset_x'); ?>"><?php _e('Left Preview Offset X', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_left_offset_x'); ?>" name="<?php echo $this->get_field_name('rokstories_left_offset_x'); ?>" type="text" value="<?php echo $rokstories_left_offset_x; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_left_offset_y'); ?>"><?php _e('Left Preview Offset Y', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_left_offset_y'); ?>" name="<?php echo $this->get_field_name('rokstories_left_offset_y'); ?>" type="text" value="<?php echo $rokstories_left_offset_y; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_right_offset_x'); ?>"><?php _e('Right Preview Offset X', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_right_offset_x'); ?>" name="<?php echo $this->get_field_name('rokstories_right_offset_x'); ?>" type="text" value="<?php echo $rokstories_right_offset_x; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_right_offset_y'); ?>"><?php _e('Right Preview Offset Y', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_right_offset_y'); ?>" name="<?php echo $this->get_field_name('rokstories_right_offset_y'); ?>" type="text" value="<?php echo $rokstories_right_offset_y; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_left_f_offset_x'); ?>"><?php _e('Left Fixed Preview Offset X', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_left_f_offset_x'); ?>" name="<?php echo $this->get_field_name('rokstories_left_f_offset_x'); ?>" type="text" value="<?php echo $rokstories_left_f_offset_x; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_left_f_offset_y'); ?>"><?php _e('Left Fixed Preview Offset Y', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_left_f_offset_y'); ?>" name="<?php echo $this->get_field_name('rokstories_left_f_offset_y'); ?>" type="text" value="<?php echo $rokstories_left_f_offset_y; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_right_f_offset_x'); ?>"><?php _e('Right Fixed Preview Offset X', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_right_f_offset_x'); ?>" name="<?php echo $this->get_field_name('rokstories_right_f_offset_x'); ?>" type="text" value="<?php echo $rokstories_right_f_offset_x; ?>" /></label>
    	<br /><br />
    	<label for="<?php echo $this->get_field_id('rokstories_right_f_offset_y'); ?>"><?php _e('Right Fixed Preview Offset Y', 'rokstories'); ?>&nbsp;
    	<input style="width: 60px;" id="<?php echo $this->get_field_id('rokstories_right_f_offset_y'); ?>" name="<?php echo $this->get_field_name('rokstories_right_f_offset_y'); ?>" type="text" value="<?php echo $rokstories_right_f_offset_y; ?>" /></label>
    	<br /><br />
    	<hr style="border: none; border-bottom: 1px dashed #919191;" />
        <h3><?php _e('Debug Information', 'rokstories'); ?></h3>
        <?php
        
        _e('GD2 Library Present: ', 'rokstories');
        
        if (extension_loaded('gd') && function_exists('gd_info')) {
    		echo '<span style="color: #177F08; font-weight: bold;">'.__('YES', 'rokstories').'</span>';
		} else {
			echo '<span style="color: #C30C0C; font-weight: bold;">'.__('NO', 'rokstories').'</span>';
		}
        
        echo '<br />';
        _e('Cache Directory Writeable: ', 'rokstories');
        
		if (is_writeable($rokstories_plugin_path . '/cache')) {
    		echo '<span style="color: #177F08; font-weight: bold;">'.__('YES', 'rokstories').'</span><br /><br />';
		} else {
			echo '<span style="color: #C30C0C; font-weight: bold;">'.__('NO', 'rokstories').'</span><br /><br />';
		}
		
		?>
		
		</div>
		<div class="clear"></div>
		
		<?php
  	
	}
}

function RokStoriesInit() {
  global $platform;
  if($platform != 'iphone') :
	  register_widget('RokStoriesWidget');
  endif;
}

add_action('widgets_init', 'RokStoriesInit');

// Load Language

load_plugin_textdomain('rokstories', false, basename($rokstories_plugin_path).'/languages/');

// MooTools Enqueue Script

add_action('init','rokstories_mootools_init',-50);
function rokstories_mootools_init(){
	global $rokstories_plugin_path, $rokstories_plugin_url;
    wp_register_script('mootools.js', $rokstories_plugin_url.'/js/mootools.js');
	wp_enqueue_script('mootools.js');
}

// Add scripts

if(!is_admin() && $platform != 'iphone') {

	function rokstories_script() {
		
		global $rokstories_plugin_path, $rokstories_plugin_url;
		
		wp_register_script('rokstories.js', $rokstories_plugin_url.'/js/rokstories.js');
		wp_register_style('rokstories.css', $rokstories_plugin_url.'/css/rokstories.css');
		
		wp_enqueue_script('rokstories.js');
		wp_enqueue_style('rokstories.css');
	
		// Load style for ie6 or ie7 if exist
	
		$iebrowser = getBrowser();
		if ($iebrowser) {
			if (file_exists($rokstories_plugin_path . "/css/rokstories-ie$iebrowser.php")) {
				wp_register_style('rokstories-ie'.$iebrowser.'.php', $rokstories_plugin_url.'/css/rokstories-ie'.$iebrowser.'.php');
				wp_enqueue_style('rokstories-ie'.$iebrowser.'.php');
			}
			elseif (file_exists($rokstories_plugin_path . "/css/rokstories-ie$iebrowser.css")) {
			    wp_register_style('rokstories-ie'.$iebrowser.'.css', $rokstories_plugin_url.'/css/rokstories-ie'.$iebrowser.'.css');
				wp_enqueue_style('rokstories-ie'.$iebrowser.'.css');
			}
		}		
	
	}
	
	function rokstories_script_inline() {	
		echo '<script type="text/javascript">var RokStoriesImage = {}, RokStoriesLinks = {};</script>'."\n";	
	}

	add_action('wp_head', 'rokstories_script', 7);
	add_action('wp_head', 'rokstories_script_inline');
	
}

// Identify browser

if(!function_exists('getBrowser')) {

	function getBrowser() {
	
		$agent = (isset($_SERVER['HTTP_USER_AGENT'])) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : false;
		$ie_version = false;
				
		if (preg_match("/msie/", $agent) && !preg_match("/opera/", $agent)){
	        $val = explode(" ",stristr($agent, "msie"));
	        $ver = explode(".", $val[1]);
			$ie_version = $ver[0];
			$ie_version = preg_replace("#[^0-9,.,a-z,A-Z]#i", "", $ie_version);
		}
		
		return $ie_version;
	
	}

}

// Add RokStories meta box

function rokstories_add_custom_box() {
     add_meta_box('rokstories_box', 'RokStories', 'rokstories_custom_box', 'post', 'normal', 'high');
     add_meta_box('rokstories_box', 'RokStories', 'rokstories_custom_box', 'page', 'normal', 'high');
}

function rokstories_custom_box() {
	global $post;
	$image = get_post_meta($post->ID,'_rokstories_image',true);	
	echo '<input type="hidden" name="rokstories_noncename" id="rokstories_noncename" value="'.wp_create_nonce('rt_rokstories').'" />';
	echo '<p>'.__('Please use links only to images that are located on the same server as your WordPress site. If automatic thumbnails aren\'t working for you please check if the <b>cache</b> directory inside of the RokStories plugin dir has proper permissions.', 'rokstories').'<br /><br />';
	echo '<label for="rt_image_box">'.__('Image Path:', 'rokstories').'</label> ';
	echo '<input type="text" class="code" value="'.$image.'" id="rt_image_box" name="rt_image_box" style="width:99%;" /></p>';
}

function rokstories_save_data($post_id) {
     // verify this with nonce because save_post can be triggered at other times
     if (!wp_verify_nonce($_POST['rokstories_noncename'], 'rt_rokstories')) return $post_id;
     
     // do not save if this is an auto save routine
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;

     $rt_image_box = trim($_POST['rt_image_box']);
     if($rt_image_box != '') :
    	 update_post_meta($post_id, '_rokstories_image', $rt_image_box);
	 else:
	 	 delete_post_meta($post_id, '_rokstories_image');
	 endif;
}

add_action('save_post', 'rokstories_save_data');
add_action('admin_menu', 'rokstories_add_custom_box');

/* Strip Only Function */

if(!function_exists('strip_only_tags')) {
	function strip_only_tags($str, $tags, $stripContent=false) {
	    $content = '';
	    if(!is_array($tags)) {
	        $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
	        if(end($tags) == '') array_pop($tags);
	    }
	    foreach($tags as $tag) {
	        if ($stripContent)
	             $content = '(.+</'.$tag.'(>|\s[^>]*>)|)';
	         $str = preg_replace('#</?'.$tag.'(>|\s[^>]*>)'.$content.'#is', '', $str);
	    }
	    return $str;
	}
}

// Experimental image resize

/*
 * Resize images dynamically using wp built in functions
 * Victor Teixeira
 *
 * php 5.2+
 *
 * Example of use :
 * 
 * <?php 
 * $thumb = get_post_thumbnail_id(); 
 * $image = rokstories_resize( $thumb, '', 140, 110, true );
 * ?>
 * <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" />
 *
 * @param int $attach_id
 * @param string $img_url
 * @param int $width
 * @param int $height
 * @param bool $crop
 * @return array
 */
 
if(!function_exists('rokstories_resize')) {
	function rokstories_resize( $attach_id = null, $img_url = null, $width, $height, $crop = false ) {
	
		global $rokstories_plugin_path, $rokstories_plugin_url;
	
		// this is an attachment, so we have the ID
		if ( $attach_id ) {
		
			$image_src = wp_get_attachment_image_src( $attach_id, 'full' );
			$file_path = get_attached_file( $attach_id );
		
		// this is not an attachment, let's use the image url
		} else if ( $img_url ) {
			
			$file_path = parse_url( $img_url );
			$file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
			
			//$file_path = ltrim( $file_path['path'], '/' );
			//$file_path = rtrim( ABSPATH, '/' ).$file_path['path'];
			
			$orig_size = @getimagesize( $file_path );
			
			$image_src[0] = $img_url;
			$image_src[1] = $orig_size[0];
			$image_src[2] = $orig_size[1];
		}
		
		$file_info = pathinfo( $file_path );
		$extension = '.'. $file_info['extension'];
	
		// the image path without the extension
		$no_ext_path = $rokstories_plugin_path.'/cache/'.$file_info['filename'];
	
		$cropped_img_path = $no_ext_path.'-'.$width.'x'.$height.$extension;
	
		// checking if the file size is larger than the target size
		// if it is smaller or the same size, stop right here and return
		if ( $image_src[1] > $width || $image_src[2] > $height ) {
	
			// the file is larger, check if the resized version already exists (for $crop = true but will also work for $crop = false if the sizes match)
			if ( file_exists( $cropped_img_path ) ) {
	
				$default_url = str_replace(basename($image_src[0]), basename($cropped_img_path), $image_src[0]);
				$cropped_img_url = str_replace(dirname($image_src[0]), $rokstories_plugin_url.'/cache', $default_url);
				
				$vt_image = array (
					'url' => $cropped_img_url,
					'width' => $width,
					'height' => $height
				);
				
				return $vt_image;
			}
	
			// $crop = false
			if ( $crop == false ) {
			
				// calculate the size proportionaly
				$proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height );
				$resized_img_path = $no_ext_path.'-'.$proportional_size[0].'x'.$proportional_size[1].$extension;		
	
				// checking if the file already exists
				if ( file_exists( $resized_img_path ) ) {
				
					$default_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] );
					$resized_img_url = str_replace(dirname($image_src[0]), $rokstories_plugin_url.'/cache', $default_url);
	
					$vt_image = array (
						'url' => $resized_img_url,
						'width' => $proportional_size[0],
						'height' => $proportional_size[1]
					);
					
					return $vt_image;
				}
			}
	
			// no cache files - let's finally resize it
			$new_img_path = image_resize( $file_path, $width, $height, $crop, '', $rokstories_plugin_path.'/cache' );
			$new_img_size = getimagesize( $new_img_path );
			$default_url = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
			$new_img = str_replace(dirname($image_src[0]), $rokstories_plugin_url.'/cache', $default_url);
	
			// resized output
			$vt_image = array (
				'url' => $new_img,
				'width' => $new_img_size[0],
				'height' => $new_img_size[1]
			);
			
			return $vt_image;
		}
	
		// default output - without resizing
		$vt_image = array (
			'url' => $image_src[0],
			'width' => $image_src[1],
			'height' => $image_src[2]
		);
		
		return $vt_image;
	}
}

?>